package com.wn.consumer.controller;

import com.wn.bean.User;
import com.wn.consumer.feign.UserFeignClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author yellow Docter
 * @date 2022 -08-23
 * @desc
 */
@RestController
@RequestMapping("feign")
@Api(tags = "feign 消费者进行测试..")
@Slf4j
public class UserFeignConsumer {

    @Autowired
    private UserFeignClient userFeignClient;

    @ApiOperation("通过id调用userservice,提供的服务,查询user")
    @GetMapping("{id}")
    public User findUserById(@PathVariable Integer id){
        User user = userFeignClient.findUserById(id);
        log.info("id find :{}",id);
        return user;
    }

    @ApiOperation("通过id删除user")
    @DeleteMapping("{id}")
    public String deleteUserById(@PathVariable Integer id){
        String str = userFeignClient.deleteById(id);
        log.info("id delete :{}",id);
        return str;
    }


    @ApiOperation("通过put修改user")
    @PutMapping
    public String findUserById(@RequestBody User user){

        log.info("user update :{}",user);

        return userFeignClient.updateUser(user);
    }


    @ApiOperation("通过userservice,提供的服务,添加user")
    @PostMapping
    public String addUserById(@RequestBody User user){

        log.info("user add :{}",user);
        String s = userFeignClient.saveUser(user);
        return s;
    }
}
